#include <algorithm>
#include <bitset>
#include <cstdint>
#include <iostream>
#include <istream>
#include <vector>
using ll = int64_t;
#define sl static inline
const ll maxn = 1e5+7;
ll n,a[maxn][4],ans,club[4];
struct S{
    ll diff,raw,i,j;
    inline bool operator<(const S&o)const{
        if(diff==o.diff)return raw>o.raw;
        return diff>o.diff;
    }
};
std::vector<S>s;
std::bitset<maxn> vis;

sl void solve(){
    std::cin>>n;
    ans=0;
    vis.reset();
    s.clear();
    club[1]=club[2]=club[3]=0;
    for(ll i=1;i<=n;i++){
        std::cin>>a[i][1]>>a[i][2]>>a[i][3];
    }
    for(ll i=1;i<=n;i++){
        ll tmp[4];
        for(ll j=1;j<=3;j++)tmp[j]=a[i][j];
        std::sort(tmp+1,tmp+4);
        for(ll j=1;j<=3;j++){
            s.push_back({a[i][j]-tmp[2],a[i][j],i,j});
        }
    }
    std::sort(s.begin(),s.end());
    for(const auto[diff,raw,i,j]:s){
        if(vis[i])continue;
        if(club[j]>=n/2)continue;
        vis[i]=true;
        club[j]++;
        ans+=raw;
    }
    std::cout<<ans<<"\n";
}

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);

    ll t;
    std::cin>>t;
    while(t--)solve();
}